package cn.weekimwee.firstlineofcodeforkotlin.unit9

import android.os.Bundle
import cn.weekimwee.firstlineofcodeforkotlin.BaseActivity
import cn.weekimwee.firstlineofcodeforkotlin.R
import kotlinx.android.synthetic.main.activity_http_urlconnection.*
import okhttp3.OkHttpClient
import okhttp3.Request

/**
 * Created by Wee Kim Wee on 2018/3/12.
 */
class OkHttpActivity :BaseActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_http_urlconnection)
        send_requst.setOnClickListener {
            Thread({
                val client = OkHttpClient()
                val requst = Request.Builder().url("http://www.baidu.com").build()
                val response = client.newCall(requst).execute()
                runOnUiThread {
                    text.text = response.body()?.string()
                }
            }).start()
        }
    }
}